package com.egene.tw.activity.wiki;

import android.text.Html;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.egene.tw.R;
import com.egene.tw.base.RecycleBaseAdapter;
import com.egene.tw.model.WikiArticle;
import com.egene.tw.utils.ImageUtil;

public class WikiRecycleAdapter extends RecycleBaseAdapter {


    public WikiRecycleAdapter() {
    }

    public WikiRecycleAdapter(View headerView) {
        mHeaderView = headerView;
    }

    @Override
    public View onCreateItemView(ViewGroup parent, int viewType) {
        return getLayoutInflater(parent.getContext()).inflate(R.layout.item_know, null);
    }

    @Override
    protected RecycleBaseAdapter.ViewHolder onCreateItemViewHolder(View view, int viewType) {
        return new ViewHolder(viewType, view);
    }

    @Override
    protected void onBindItemViewHolder(RecycleBaseAdapter.ViewHolder vh, int position) {
        super.onBindItemViewHolder(vh, position);
        WikiRecycleAdapter.ViewHolder holder = (WikiRecycleAdapter.ViewHolder) vh;
        WikiArticle article = (WikiArticle) _data.get(position);
//        if (!TextUtils.isEmpty(article.getImg_url())) {
//            Picasso.with(holder.ivHead.getContext()).load(EgeneApi.BASE_URL + article.getImg_url()).into(holder.ivHead);
//        }
        ImageUtil.loadImage(holder.ivHead.getContext(), holder.ivHead, article.getImg_url());

        holder.tvTitle.setText(article.getTitle());
        holder.tvContent.setText(Html.fromHtml(article.getZhaiyao()));
    }

    public static class ViewHolder extends RecycleBaseAdapter.ViewHolder {
        public ImageView ivHead;
        public TextView tvTitle;
        public TextView tvContent;


        public ViewHolder(int viewType, View view) {
            super(viewType, view);
            ivHead = (ImageView) view.findViewById(R.id.ivHead);
            tvTitle = (TextView) view.findViewById(R.id.tvTitle);
            tvContent = (TextView) view.findViewById(R.id.tvContent);
        }
    }
}
